package com.miaozhen.datainsight.web.jobMessaging;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.config.KafkaListenerEndpointRegistry;
import org.springframework.kafka.listener.MessageListener;
import org.springframework.stereotype.Component;

/**
 * 用于从消息队列中获取并处理 任务状态的消息.
 * 配置了自动commit
 *
 * @author tzp
 * @date 2017/11/13
 */
@Component
@Slf4j
public class JobStateListener implements MessageListener<String, String> {


    @Override
    public void onMessage(ConsumerRecord<String, String> record) {
        log.info("myreceive" + record.key() + " " + record.value());
    }

    /**
     * job状态结果的消息体
     */
    @Data
    public class JobStateMessage {
        private Long totalCount;
        private Long uniqCount;
        private Long effectCount;
        private Long coveredCount;
        /**
         * 频次达成:
         * <pre>
         * "media-type" : [
         *   {
         *     "type": "",
         *     "day_count": "x,x,x,x,x,x,x,x,x" //频次达成2~10所需天数
         *   },
         *   ...
         * ],
         * "online-video": [
         *   {
         *     "media" : "",
         *     "day_count": "x,x,x,x,x,x,x,x,x" //频次达成2~10所需天数
         *   },
         *   ...
         * ]
         * </pre>
         */
        private String freqReach;
    }
}
